package cn.itcast.mq.listern;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class SpringRabbitListener {

    @RabbitListener(queues ="simple.queue" )
    public void listenSimpleQueueMessage1(String msg) throws InterruptedException {
        System.out.println("spring 消费者1 接收到消息：【" + msg + "】");

    }

    @RabbitListener(queues ="simple.queue" )
    public void listenSimpleQueueMessage2(String msg) throws InterruptedException {
        System.out.println("spring 消费者2接收到消息：【" + msg + "】");
//        Thread.sleep(2000);
    }

    @RabbitListener(queues ="fanout.queue1" )
    public void listenFanoutQueueMessage1(String msg) throws InterruptedException {
        System.out.println("spring 消费者1接收到消息：【" + msg + "】");
//        Thread.sleep(2000);
    }

    @RabbitListener(queues ="fanout.queue2" )
    public void listenFanoutQueueMessage2(String msg) throws InterruptedException {
        System.out.println("spring 消费者2接收到消息：【" + msg + "】");
//        Thread.sleep(2000);
    }


    @RabbitListener(bindings = @QueueBinding(
            value=@Queue("direct.queue1"),
            exchange = @Exchange(value = "itcast.direct",type = ExchangeTypes.DIRECT),
            key ={"blue","red"}
    ))
    public void listenDirectQueueMessage1(String msg) throws InterruptedException {
        System.out.println("spring 消费者1接收到消息：【" + msg + "】");
//        Thread.sleep(2000);
    }

    @RabbitListener(bindings = @QueueBinding( value=@Queue("direct.queue2"),
            exchange = @Exchange(value = "itcast.direct",type = ExchangeTypes.DIRECT),
            key ={"yellow","red"} ))
    public void listenDirectQueueMessage2(String msg) throws InterruptedException {
        System.out.println("spring 消费者2接收到消息：【" + msg + "】");
//        Thread.sleep(2000);
    }
    @RabbitListener(bindings = @QueueBinding(
            value=@Queue("topic.queue1"),
            exchange = @Exchange(value = "itcast.topic",type = ExchangeTypes.TOPIC),
            key="China.#"
    ))
    public void listenTopicQueueMessage1(String msg) throws InterruptedException {
        System.out.println("spring 消费者1接收到消息：【" + msg + "】");
//        Thread.sleep(2000);
    }

    @RabbitListener(bindings = @QueueBinding(
            value=@Queue("topic.queue2"),
            exchange = @Exchange(value = "itcast.topic",type = ExchangeTypes.TOPIC),
            key="China.#"
    ))
    public void listenTopicQueueMessage2(String msg) throws InterruptedException {
        System.out.println("spring 消费者2接收到消息：【" + msg + "】");
//        Thread.sleep(2000);
    }
}
